package learn.basics.string1;

class Dmeo1String {
    public static void Test() {

        String str1 = new String();
        System.out.println(str1);

        char[] char_array = {'A', 'C', 'B'};

        String str2 = new String(char_array);
        System.out.println("str2：" + str2);

        String str3 = "hello";
        System.out.println("str3: " + str3);
    }
}

class Demo2StringPool {
    public static void Test() {
        String s1 = "abc";
        String s2 = "abc";

        char[] char_array = {'a', 'b', 'c'};
        String s3 = new String(char_array);

        System.out.println(s1 == s2);
        System.out.println(s1 == s3);
        System.out.println(s2 == s3);
    }
}

class Demo01StringEquals {
    public static void Test() {
        String s1 = "hello";
        String s2 = "hello";

        char[] char_array = {'h', 'e', 'l', 'l', 'o'};
        String s3 = new String(char_array);

        //值比较
        System.out.println(s1.equals(s2));
        System.out.println(s2.equals(s3));
        System.out.println(s3.equals("hello"));

        String s4 = "Hello";
        System.out.println(s1.equals(s4));
        System.out.println("==============================");

        String s5 = null;
        System.out.println("abc".equals(s5));

        System.out.println("===============================");

        String sa = "JAVA";
        String sb = "java";

        System.out.println(sa.equals(sb));
        System.out.println(sa.equalsIgnoreCase(sb));
    }

}

class Demo02StringGet {

    public static void Test(){
        int len="abc".length();
        System.out.println("len="+len);

        String s1="Hello";
        String s2="World";
        String s3=s1.concat(s2);
        System.out.println("s1="+s1);
        System.out.println("s2="+s2);
        System.out.println("s3="+s3);

        System.out.println("===========================");

        char ch="Hello".charAt(1);
        System.out.println(ch);
        System.out.println("===========================");

        String original="HelloWorldHelloWorld";
        int index=original.indexOf("llo");
        System.out.println(index);

    }
}

class Demo03Substring{
    public static void Test(){
        String s1="HelloWorld";
        String s2=s1.substring(5);
        System.out.println(s1);
        System.out.println(s2);

        System.out.println("====================");

        String s3=s1.substring(4,7);
        System.out.println(s3);
        System.out.println("=========================");

        String sa="hello";
        System.out.println(sa);
        sa="java";
        System.out.println(sa);
    }
}

class Demo04StringConvert{
    public static void Test(){
        char[] chars="hello".toCharArray();
        System.out.println(chars[0]);
        System.out.println(chars.length);
        System.out.println("=====================");

        byte[] bytes="abc".getBytes();
        for(int i=0;i<bytes.length;i++){
            System.out.print(bytes[i]+ " ");
        }
        System.out.println();
        System.out.println("====================");

        //字符串内容转换
        String s1="how do you do?";
        String s2=s1.replace("o","*");
        System.out.println(s1);
        System.out.println(s2);
        System.out.println("================");
    }
}

class DemoStringSplit{
    public static void Test(){
        String s1="aaa,bbb,ccc";
        String [] array=s1.split(",");
        for(int i=0;i<array.length;i++){
            System.out.print(array[i]+ " ");
        }
        System.out.println();

        System.out.println("======================");

        String s2="aaa.bbb.ccc";
        String []array2=s2.split("\\.");
        System.out.println(array2.length);
        for(int i=0;i<array2.length;i++){
            System.out.print(array2[i]+ " ");
        }
    }
}

class Demo06StringPractise{

}




public class TestString {

    public static void main(String[] args) {
        //Dmeo1String.Test();
        //Demo2StringPool.Test();
        //Demo01StringEquals.Test();
        //Demo02StringGet.Test();
        //Demo03Substring.Test();
        //Demo04StringConvert.Test();
        //DemoStringSplit.Test();
    }
}


